package com.azusa.xbjy.entity;

import com.fasterxml.jackson.annotation.JsonFormat;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name = "article")
public class Article {
    private int id;

    @Id
    @javax.persistence.Column(name = "id", table = "article", nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    private String title;

    @Basic
    @javax.persistence.Column(name = "title", table = "article", nullable = true, length = 50)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    private String content;

    @Basic
    @javax.persistence.Column(name = "content", table = "article", nullable = true, length = 5000)
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    private Integer browseCount;

    @Basic
    @javax.persistence.Column(name = "browse_count", table = "article", nullable = true)
    public Integer getBrowseCount() {
        return browseCount;
    }

    public void setBrowseCount(Integer browseCount) {
        this.browseCount = browseCount;
    }

    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss")
    private Date publishDate;

    @Basic
    @javax.persistence.Column(name = "publish_date", table = "article", nullable = true)
    public Date getPublishDate() {
        return publishDate;
    }

    public void setPublishDate(Date publishDate) {
        this.publishDate = publishDate;
    }

    private String publishRealName;

    @Basic
    @javax.persistence.Column(name = "publish_real_name", table = "article", nullable = true, length = 50)
    public String getPublishRealName() {
        return publishRealName;
    }

    public void setPublishRealName(String publishRealName) {
        this.publishRealName = publishRealName;
    }

    private Integer userId;

    @Basic
    @javax.persistence.Column(name = "user_id", table = "article", nullable = false)
    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    //判断是否有被收藏
    private boolean collect = false;

    @Transient
    public boolean isCollect() {
        return collect;
    }

    public void setCollect(boolean collect) {
        this.collect = collect;
    }

    //收藏数
    private int count;

    @Transient
    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Article article = (Article) o;

        if (id != article.id) return false;
        if (title != null ? !title.equals(article.title) : article.title != null) return false;
        if (content != null ? !content.equals(article.content) : article.content != null) return false;
        if (browseCount != null ? !browseCount.equals(article.browseCount) : article.browseCount != null) return false;
        if (publishDate != null ? !publishDate.equals(article.publishDate) : article.publishDate != null) return false;
        if (publishRealName != null ? !publishRealName.equals(article.publishRealName) : article.publishRealName != null)
            return false;
        return userId != null ? userId.equals(article.userId) : article.userId == null;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (content != null ? content.hashCode() : 0);
        result = 31 * result + (browseCount != null ? browseCount.hashCode() : 0);
        result = 31 * result + (publishDate != null ? publishDate.hashCode() : 0);
        result = 31 * result + (publishRealName != null ? publishRealName.hashCode() : 0);
        result = 31 * result + (userId != null ? userId.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Article{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", content='" + content + '\'' +
                ", browseCount=" + browseCount +
                ", publishDate=" + publishDate +
                ", publishRealName='" + publishRealName + '\'' +
                ", userId=" + userId +
                '}';
    }
}
